package com.maxatime.service.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.maxatime.dao.ExamPlanMapper;
import com.maxatime.pojo.entity.ExamPlan;
import com.maxatime.service.ExamPlanService;
import com.maxatime.util.SerialNumberUtil;

@Service
public class ExamPlanServiceImpl implements ExamPlanService{
	
	@Autowired
	ExamPlanMapper examPlanMapper;
	@Override
	public int deleteByPrimaryKey(Integer pkId) {
		// TODO Auto-generated method stub
		return examPlanMapper.deleteByPrimaryKey(pkId);
	}

	@Override
	public int insert(ExamPlan record) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int insertSelective(ExamPlan record) {
		// TODO Auto-generated method stub
		ExamPlan examPlan = new ExamPlan();
		BeanUtils.copyProperties(record, examPlan);
		Date d = new Date();
		examPlan.setUpdateDate(d);
		examPlan.setCreateDate(d);
		examPlan.setDeleteFlag("0");
		int examPlanId = Integer.valueOf(SerialNumberUtil.getRandomNum());
		examPlan.setExamPlanId(examPlanId);
		examPlanMapper.insertSelective(examPlan);
		return 0;
	}

	@Override
	public ExamPlan selectByPrimaryKey(Integer pkId) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int updateByPrimaryKeySelective(ExamPlan record) {
		// TODO Auto-generated method stub
		ExamPlan examPlan = new ExamPlan();
		BeanUtils.copyProperties(record, examPlan);
		Date d = new Date();
		examPlan.setUpdateDate(d);
		examPlanMapper.updateByPrimaryKeySelective(examPlan);
		return 0;
	}

	@Override
	public int updateByPrimaryKey(ExamPlan record) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public Map<String, Object> list(ExamPlan examPlan) {
		// TODO Auto-generated method stub
		PageHelper.startPage(examPlan.getPageNum(), examPlan.getPageSize());
		List<ExamPlan> examPlan1 = examPlanMapper.list(examPlan);
		PageInfo<ExamPlan> pageInfo = new PageInfo<ExamPlan>(examPlan1);
		Map<String, Object> m = new HashMap<>();
		m.put("examPlan1", examPlan1);
		m.put("pageInfo", pageInfo);
		
		return m;
	}

	@Override
	public ExamPlan find(int pkId) {
		// TODO Auto-generated method stub
		return examPlanMapper.find(pkId);
	}

}
